package com.ojoin.trade.supplyloan_core.utils.catchdata.httpclient;

import org.apache.http.impl.client.CloseableHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ojoin.trade.common.utils.LogUtils;
import com.ojoin.trade.supplyloan_core.utils.catchdata.MyCatchDateUtill;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlPlatformUser;

public class MyCloseableHttpClient implements MyCatchDateUtill{
	private static  Logger log = LoggerFactory
			.getLogger(MyCloseableHttpClient.class); 
	
	public static MyCloseableHttpClient get( TbSlPlatformUser platformUser) {
		// this.setPlatformUser(platformUser);
		MyCloseableHttpClient driver = null;

		String PlatformName = platformUser.getPlatformName();
		String username = platformUser.getUsername();

		
		if (driver == null) {
			driver = prepareCatchData(platformUser);
		}
		return driver;
	}
	
	
	public static MyCloseableHttpClient prepareCatchData(TbSlPlatformUser platformUser) {
		MyCloseableHttpClient driver = null;

		LogUtils.info(log, "platformName->" + platformUser.getPlatformName()
				+ " joinid->" + platformUser.getIdOfTbMerchantUser()
				+ " username->" + platformUser.getUsername()
				+ "getDriver-->prepareMyWebDriver");

		driver = new MyCloseableHttpClient();
		driver.setPlatformUser(platformUser);
		CloseableHttpClient my;
		try {
			my = driver.create();
			driver.setHttpClient(my);
		} catch (Exception e) {
			
		}

		return driver;

	}
	


	private TbSlPlatformUser platformUser;
	private CloseableHttpClient httpClient ; 
	private boolean islogin = false ;
	private boolean isCache = false ;
	
	
    public TbSlPlatformUser getPlatformUser() {
		return platformUser;
	}


	public void setPlatformUser(TbSlPlatformUser platformUser) {
		this.platformUser = platformUser;
	}


	public boolean isIslogin() {
		return islogin;
	}


	public void setIslogin(boolean islogin) {
		this.islogin = islogin;
	}

 
	/*private MyWebDriver(){
    }*/
	
	public boolean isCache() {
		return isCache;
	}


	public void setCache(boolean isCache) {
		this.isCache = isCache;
	}


	

	public CloseableHttpClient getHttpClient() {
		return httpClient;
	}
 

	public void setHttpClient(CloseableHttpClient httpClient) {
		this.httpClient = httpClient;
	}

	@Override
	// 初始化状态
	public void init(){
		this.setIslogin(false);
		this.setPlatformUser(null);
	}
	
	public int getDefaultDriverTimeOut() {
		return 30;
	}


	@Override
	public CloseableHttpClient create() {
		CloseableHttpClient client = HttpClientUtil.getHttpclient();
		return client; 
	}

	@Override
	public void close(boolean isuser) {
		
		
	}
	 
	@Override
	public byte[] getIMGByte(Object o) {
		
		return null;
	}

	@Override
	public String getVerifyCode(Object o) {
		
		return null;
	}
	
}
